import { createStore } from 'vuex';
import { getToken, setToken } from '@/utils/storage'

export default createStore({
    state: {
        token: getToken()?.token || null,
        username: getToken()?.username || '',
    },
    mutations: {
        login(state,payload) {
            state.token = payload.token;
            setToken(payload.token);
            state.username = payload.username;
        },
        logout(state) {
            state.token = null;
            setToken({});
            state.username = '';
        }
    },
    actions: {},
    modules: {},
});
